package com.example.module_service.vm

import com.example.lib_common.view.vm.BaseViewModel
import com.example.module_service.api.ServiceApiService
import com.example.module_service.entity.CarPayEntity
import com.example.module_service.entity.MerchantEntity
import com.example.module_service.entity.MerchantEntityItem
import com.example.module_service.model.ServiceRepository
import com.example.module_service.model.ServiceResultData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MerchantViewModel @Inject constructor(
    private val apiService: ServiceApiService
):BaseViewModel<ServiceRepository,ServiceResultData<List<MerchantEntityItem>>>(){

    fun getListData(){
        mViewModelScope.launch(mDispatcher){
            try {
                val resultData = apiService.getMerchant()
                val res = ServiceResultData(
                    resultData.code,
                    resultData.data,
                    resultData.message
                )
                mSuccessLiveData.postValue(res)
            } catch (e: Exception) {
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }

}